import os

import sys
import pytest
import requests

from conf.readconf import ReadConf

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))


#  crm登录，返回token,全局都可以去使用
@pytest.fixture(scope="session")
def crm_login():
    rc = ReadConf()
    url = rc.get_crm("crm_url")
    parm = {"username": 18329799711, "password": 123456}
    head = {"Content-Type": "application/x-www-form-urlencoded"}
    result = requests.post(url + "/login", data=parm, headers=head, timeout=2)
    # print(result.json()["Admin-Token"])
    return result.json()["Admin-Token"]
